<?php
class kst_kode_io_barang_model extends MY_Model {
	var $model = 'kst_kode_io_barang';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	kst_kode_io_barang
					WHERE	(UPPER(kb_kode) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kb_nama) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kb_posisi) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kb_kode' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('kst_kode_io_barang', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('kst_kode_io_barang', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kb_kode){
		$result = $this->db->get_where('kst_kode_io_barang', array('kb_kode' => $as_kb_kode));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kb_kode)
	{
		$result = $this->db->get_where('kst_kode_io_barang', array('kb_kode' => $as_kb_kode));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM kst_kode_io_barang WHERE kb_kode = '".$arr_rule['kb_kode']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['kb_kode']."]<br />";
			}else{
				$this->db->delete('kst_kode_io_barang', array('kb_kode' => $arr_rule['kb_kode']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>